package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.ProductDao;
import ysq.xyg.model.BaseDepart;
import ysq.xyg.model.Product;
import ysq.xyg.model.Relay;
import ysq.xyg.service.ProductService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-04-19 14:11
 **/
@Service("productService")
public class ProductServiceImpl extends BaseServiceImpl<Product> implements ProductService {
    @Resource
    private ProductDao productDao;
    @Autowired
    public void setProductDao(ProductDao productDao) {
        this.baseDao = productDao;
    }

    //分页查询
    public PageInfo<Product> pageInfo(Product product, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        Example example = new Example(Product.class);
        Example.Criteria criteria = example.createCriteria();
        List<Product> list=productDao.selectByExample(example);
        return new PageInfo<Product>(list);
    }

    public PageInfo<Product> pageInfoLeft(Product product, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> list=productDao.selectListLeft(product);
        return new PageInfo<Product>(list);
    }
    public PageInfo<Product> pageInfoLeftK(Product product, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> list=productDao.selectListLeftK(product);
        return new PageInfo<Product>(list);
    }
    public List<Product> listLeft(Product product) {
        List<Product> list=productDao.selectListLeft(product);
        return list;
    }
    public List<Product> listLeftK(Product product) {
        List<Product> list=productDao.selectListLeftK(product);
        return list;
    }
    public Product selectById(String id) {
        Product product=new Product();
        product.setId(id);
        List<Product> list=productDao.selectListLeft(product);
        if(list!=null && list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }
    public List<Product> list(Product product) {
        Example example = new Example(Product.class);
        Example.Criteria criteria = example.createCriteria();
        if(product!=null){
            if(StringUtil.isNotEmpty(product.getDeviceId())){
                criteria.andEqualTo("deviceId",product.getDeviceId());
            }
        }
        List<Product> list=productDao.selectByExample(example);
        return list;
    }
    public List<Product> selectDataList(Product product){
        return productDao.selectDataList(product);
    }
    public int selectEntityCount(Product product){
        return productDao.selectEntityCount(product);
    }
    public Product selectData(Product product){
        return productDao.selectData(product);
    }

    public void updateByOpenid(Product product){
        productDao.updateByOpenid(product);
    }

}
